﻿using Grpc.Core;

namespace XLZF.MicroServices.IDS4.Service;

public class GetUsersService : Users.UsersBase
{
    private readonly ILogger<GetUsersService> _logger;

    private readonly ApplicationDbContext _dbContext;

    public GetUsersService(ILogger<GetUsersService> logger, ApplicationDbContext dbContext)
    {
        _logger = logger;

        _dbContext = dbContext;
    }

    public override Task<UserModelReply> GetUserModel(GetUserRequest request, ServerCallContext context)
    {
        var list = _dbContext.Users.Where(p => p.Validity == true).ToList();

        var liss = from li in list
                   select new Person
                   {
                       Id = li.Id,
                       Nickname = li.NickName
                   };

        UserModelReply replyModel = new UserModelReply();

        replyModel.Person.AddRange(liss.ToList());

        return Task.FromResult(replyModel);
    }
}
